package com.heiye.blog.ai.factory;

import com.google.common.collect.Maps;
import com.heiye.blog.ai.enums.RoleNameEnum;
import com.heiye.blog.ai.strategy.role.RoleStrategy;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.Map;

/**
 * @author: heiye
 * @date: 2025/11/19 下午2:22
 * @version: v1.0.0
 * @description: 角色策略工厂
 */
@Configuration
public class RoleStrategyFactory {
    /**
     * 该处存放所有文本模型策略 --- 自动装配
     */
    @Resource
    private List<RoleStrategy> roleStrategies;

    private final Map<RoleNameEnum, RoleStrategy> roleStrategyMap = Maps.newHashMap();

    /**
     * @PostConstruct： 构造方法执行完成之后执行将 textModelStrategyMap 填充
     */
    @PostConstruct
    public void init() {
        roleStrategies.forEach(roleStrategy ->
                roleStrategyMap.put(roleStrategy.getRoleNameEnum(), roleStrategy));
    }

    public RoleStrategy getStrategy(String name) {
        RoleNameEnum roleNameEnum = RoleNameEnum.getByName(name);
        return roleStrategyMap.get(roleNameEnum);
    }
}
